package com.alex.goods.service.impl;

import com.alex.goods.dao.GoodsDao;
import com.alex.goods.entity.Goods;
import com.alex.goods.service.GoodsService;

import java.time.LocalDate;
import java.util.List;

public class GoodsServiceImpl implements GoodsService {
	
	GoodsDao goodsDao = new GoodsDao();
	
	@Override
	public List<Goods> selectGoodsList(String sql, Object... params) {
		return goodsDao.selectGoodsList(sql, params);
	}
	
	@Override
	public void addGoods(Object... params) {
		goodsDao.addGoods(params);
	}

	
	@Override
	public Long getGoodsKindNumUpdate(String sqlcount) {
		return goodsDao.getGoodsKindNum(sqlcount);
	}

	@Override
	public void updateGoodsToNotUse(String goodsNo) {
		goodsDao.updateGoodsToNotUse(goodsNo);
	}

	@Override
	public void updateGoodsToUse(String goodsNo) {
		goodsDao.updateGoodsUse(goodsNo);
	}


	@Override
	public Long getGoodsKindNum() {
		String sqlcount = "select count(1) from goods";
		return goodsDao.getGoodsKindNum(sqlcount);
	}
    
	
	@Override
	public String makeGoodsNo() {
		Long pin = this.getGoodsKindNum() + 1;
		LocalDate tmp = LocalDate.now();
		String month = String.format("%2s", tmp.getMonthValue()).replaceAll(" ", "0");
		String day = String.format("%2s", tmp.getDayOfMonth()).replaceAll(" ", "0");
		String goodsNo = "" + tmp.getYear() + month + day + String.format("%6s", pin).replaceAll(" ", "0");
		return goodsNo;
	}

	@Override
	public void updateGoodsInOut(String id, String isin, String isout) {
		// TODO Auto-generated method stub
		goodsDao.updateGoodsInOut(id,isin,isout);
	}
	

}
